import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/parts/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询详情'
});
const addDesc = formatMessage({
    id: 'api.message.newVehicleSaleOrderDesc',
    defaultMessage: '新增'
});
const updateDesc = formatMessage({
    id: 'api.message.updateDesc',
    defaultMessage: '修改'
});
const confirmorDesc = formatMessage({
    id: 'api.message.confirmorDesc',
    defaultMessage: '确认'
});
const invoiceDesc = formatMessage({
    id: 'api.message.invoiceDesc',
    defaultMessage: '确认发票'
});
const abandonDesc = formatMessage({
    id: 'api.message.abandonDesc',
    defaultMessage: '作废'
});
const getPartClaimReportListDesc = formatMessage({
    id: 'api.message.getPartClaimReportListDesc',
    defaultMessage: '备件索赔报告查询'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/partClaimCacu/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partClaimCacus/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/partClaimCacus/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
// 新增
export const addApplyReport = data => request(`${baseUrl}/partClaimCacus`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, addDesc));
//修改
export const updateApplyReport = (id, data) => request(`${baseUrl}/partClaimCacus/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updateDesc));
// 确认
export const confirmorData = (id, data) => request(`${baseUrl}/partClaimCacus/${id}/confirmor`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, confirmorDesc));
// 发票确认
export const invoiceData = (id, rowVersion) => request(`${baseUrl}/partClaimCacus/${id}/invoice`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
        rowVersion
    })}).then(handleFetchResultNotification(REQUEST_TYPE.submit, invoiceDesc));
// 作废
export const abandonData = (id, rowVersion) => request(`${baseUrl}/partClaimCacus/${id}/abandon`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
        rowVersion
    })}).then(handleFetchResultNotification(REQUEST_TYPE.submit, abandonDesc));
// 备件索赔报告查询
export const getPartClaimReport = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partClaimReports/forPartClaimCacu?${queryString}`, null, dto.PartClaimReportList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getPartClaimReportListDesc));
};
